var UNIT = ["", "K", "M", "B", "T"];
for (let a = 0; a < 2; a++) {
    for (let b = 0; b < 26; b++) {
        UNIT.push(String.fromCharCode(65 + a) + String.fromCharCode(65 + b));
    }
}
export const BigNumber = {
    toBigNumber(a) {
        return new Bignumber(a);
    },
    plus(a, b) {
        a = new Bignumber(a);
        b = new Bignumber(b);
        return a.plus(b);
    },

    minus(a, b) {
        a = new Bignumber(a);
        b = new Bignumber(b);
        return a.minus(b);
    },

    div(a, b) {
        a = new Bignumber(a);
        b = new Bignumber(b);
        return a.div(b);
    },

    mult(a, b) {
        a = new Bignumber(a);
        b = new Bignumber(b);
        return a.multipliedBy(b);
    },

    pow(a, b) {
        a = new Bignumber(a);
        b = new Bignumber(b);
        return a.pow(b);
    },

    compose(a, b) {
        a = new Bignumber(a);
        b = new Bignumber(b);
        return a.comparedTo(b);
    },

    // 把bignumber转成带符号的字符串
    // 如果1.11k 11.1k 111k 1.11m
    toUnitType(a) {
        a = new Bignumber(a);
        /**
         * c 是coefficient 系数
         * e 是exponent 指数，最高位后有几个零
         * s 是sign 符号，也就是正负
         */
        let e = a.e;

        let unitIndex = Math.floor(e / 3);
        let unitE = e % 3; // 0,1,2
        let unit = UNIT[unitIndex];

        let strNum = a.toString();
        strNum = strNum.replace(/\./g,'');
        let str = String(strNum).substring(0, 3);
        
        if (str.length >= 2 && unitE != 2) {
            str = str.slice(0, unitE + 1) + '.' + str.slice(unitE + 1)
        }
        str = String(Number(str));
        return str + unit;
    },
}